package com.ruoyi.certificate.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.certificate.domain.NjtCertificate;
import com.ruoyi.certificate.service.INjtCertificateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 农检通合格证Controller
 * 
 * @author ruoyi
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/certificate/njt_certificate")
public class NjtCertificateController extends BaseController
{
    @Autowired
    private INjtCertificateService njtCertificateService;

    /**
     * 查询农检通合格证列表
     */
    @PreAuthorize("@ss.hasPermi('certificate:njt_certificate:list')")
    @GetMapping("/list")
    public TableDataInfo list(NjtCertificate njtCertificate)
    {
        startPage();
        List<NjtCertificate> list = njtCertificateService.selectNjtCertificateList(njtCertificate);
        return getDataTable(list);
    }

    /**
     * 导出农检通合格证列表
     */
    @PreAuthorize("@ss.hasPermi('certificate:njt_certificate:export')")
    @Log(title = "农检通合格证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NjtCertificate njtCertificate)
    {
        List<NjtCertificate> list = njtCertificateService.selectNjtCertificateList(njtCertificate);
        ExcelUtil<NjtCertificate> util = new ExcelUtil<NjtCertificate>(NjtCertificate.class);
        util.exportExcel(response, list, "农检通合格证数据");
    }

    /**
     * 获取农检通合格证详细信息
     */
    @PreAuthorize("@ss.hasPermi('certificate:njt_certificate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(njtCertificateService.selectNjtCertificateById(id));
    }

    /**
     * 新增农检通合格证
     */
    @PreAuthorize("@ss.hasPermi('certificate:njt_certificate:add')")
    @Log(title = "农检通合格证", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NjtCertificate njtCertificate)
    {
        return toAjax(njtCertificateService.insertNjtCertificate(njtCertificate));
    }

    /**
     * 修改农检通合格证
     */
    @PreAuthorize("@ss.hasPermi('certificate:njt_certificate:edit')")
    @Log(title = "农检通合格证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NjtCertificate njtCertificate)
    {
        return toAjax(njtCertificateService.updateNjtCertificate(njtCertificate));
    }

    /**
     * 删除农检通合格证
     */
    @PreAuthorize("@ss.hasPermi('certificate:njt_certificate:remove')")
    @Log(title = "农检通合格证", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(njtCertificateService.deleteNjtCertificateByIds(ids));
    }
}
